<?php

namespace App\System\Cms\Repositories;

use App\System\Base\Helpers\Traits\SinglePattern;
use App\System\Base\Repositories\Repository;
use Illuminate\Support\Collection;
use App\System\Cms\Model\CmsArticle;


class CmsArticleRepository extends Repository
{
    use SinglePattern;

    public function getArtilesDetil($id)
    {
        $data = CmsArticle::where('id', $id)->first();
        return $data;
    }

    public function saveArticle($id,$updata)
    {
        if (!$id) {
            return false;
        }
        $article = CmsArticle::find($id);
        $article->content = $updata['content'];
        $ret = $article->save();
        $msg = $ret?'操作成功':'操作失败！';
        return array('data' => $ret, 'message' => $msg);
    }

    /**
     *通过type获取文章详细
     */
    public function getArticleByType($type)
    {
        $data = CmsArticle::where('type', $type)->first();
        return $data;
    }

    public function getArticleTitleById($id,$field)
    {
          $data= CmsArticle::select($field)->find($id);
          if (!$data){
              return false;
          }
        return $data->getAttributeValue($field);
    }
    public function getArticleById($id)
    {
        return CmsArticle::find($id);
    }
}